﻿using Amiable.SDK.Tool.HIni;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AmiDraw.Code.Util
{
    public class UserDataUtil
    {
        public static int GetLeftTime(long userId, string name = "default")
        {
            IniObject ini = new IniObject(PathUtil.GetUserDataPath(userId));

            ini.Load();

            return ini["剩余次数"][name].ToInt32();
        }

        public static int AddLeftTime(long userId, string name = "default", int times = 1)
        {
            IniObject ini = new IniObject(PathUtil.GetUserDataPath(userId));

            ini.Load();

            ini["剩余次数"][name] = (ini["剩余次数"][name].ToInt32() + times).ToString();

            ini.Save();

            return ini["剩余次数"][name].ToInt32() ;
        }

        public static void SetCheckinTime(long userId)
        {
            IniObject ini = new IniObject(PathUtil.GetUserDataPath(userId));

            ini.Load();

            ini["签到"]["签到日期"] = DateTime.Today.ToShortTimeString();

            ini.Save();
        }

        public static bool CanCheckin(long userId)
        {
            IniObject ini = new IniObject(PathUtil.GetUserDataPath(userId));

            ini.Load();

            return ini["签到"]["签到日期"] != DateTime.Today.ToShortTimeString();
        }
    }
}
